package com.bw.cotroller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.bean.*;
import com.bw.service.MyServiceImpl;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@ResponseBody
@RequestMapping
@RestController
public class MyCotroller {
    @Resource
    MyServiceImpl myService;
    @RequestMapping("/list1")
    public Object PayOk(){
        List<ZaiXianPay> zaiXianPays = myService.PayOk();
        JSONObject o1 = new JSONObject();
        o1.put("status",0);
        o1.put("msg","");
        for (ZaiXianPay zaiXianPay : zaiXianPays) {
            o1.put("data",zaiXianPay.getCount());
        }
        return o1;
    }
    @RequestMapping("list2")
    public Object list2(){
        List<ZaixianTj> zaixianTjs = myService.list2();
        JSONObject o = new JSONObject();
        o.put("status",0);
        o.put("msg","");
        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();

        JSONObject o2 = new JSONObject();
        o2.put("name","课程名称");
        o2.put("id","subsys");

        JSONObject o3 = new JSONObject();
        o3.put("name","考试人数");
        o3.put("id","module");

        JSONObject o4 = new JSONObject();
        o4.put("name","平均分");
        o4.put("id","business");

        JSONObject o5 = new JSONObject();
        o5.put("name","平均用时");
        o5.put("id","value");
        a1.add(o2);
        a1.add(o3);
        a1.add(o4);
        a1.add(o5);
        o1.put("columns",a1);
        JSONArray a2 = new JSONArray();

        for (ZaixianTj zaixianTj : zaixianTjs) {
            JSONObject o6 = new JSONObject();
            o6.put("subsys",zaixianTj.getName());
            o6.put("module",zaixianTj.getCount());
            o6.put("business",zaixianTj.getScore());
            o6.put("value",zaixianTj.getTime());
            a2.add(o6);
        }
        o1.put("rows",a2);
        o.put("data",o1);
        return o;
    }
    @RequestMapping("list3")
    public Object list3(){
        List<ScoreZaixian> sz = myService.list3();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();
        for (ScoreZaixian scoreZaixian : sz) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",scoreZaixian.getName());
            jsonObject1.put("value",scoreZaixian.getCount());
            objects.add(jsonObject1);
        }
        jsonObject.put("data",objects);
        return jsonObject;
    }
    @RequestMapping("list4")
    public Object list4(){
        List<CItyZaiXian> cItyZaiXians = myService.list4();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();
        for (CItyZaiXian cItyZaiXian : cItyZaiXians) {
            JSONObject o2 = new JSONObject();
            o2.put("name",cItyZaiXian.getName());
            o2.put("value",cItyZaiXian.getMoney());
            a1.add(o2);
        }
        o1.put("mapData",a1);
        jsonObject.put("data",o1);
        return jsonObject;
    }
    @RequestMapping("/list5")
    public Object list5(){
        List<LiuLiangZaiXian> lz = myService.list5();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();
        for (LiuLiangZaiXian liuLiangZaiXian : lz) {
            a1.add(liuLiangZaiXian.getCount());
        }

        o1.put("categories",a1);
        JSONArray a2 = new JSONArray();
        JSONObject o2 = new JSONObject();
        o2.put("name","独立访客数");
        JSONArray a3 = new JSONArray();
        for (LiuLiangZaiXian liuLiangZaiXian : lz) {
            a3.add(liuLiangZaiXian.getSum());
        }
        o2.put("data",a3);
        a2.add(o2);

        JSONObject o3 = new JSONObject();
        o3.put("name","页面浏览数");
        JSONArray a4 = new JSONArray();
        for (LiuLiangZaiXian liuLiangZaiXian : lz) {
            a4.add(liuLiangZaiXian.getCount());
        }
        o3.put("data",a4);
        a2.add(o3);
        o1.put("series",a2);
        jsonObject.put("data",o1);
        return jsonObject;
    }
}
